﻿using Basic.WxApiService.ApiInterface;
using Basic.WxApiService.Interface;
using Basic.WxApiService.WxModel.Platform;
using WeDonekRpc.Client.Attr;

namespace Basic.WxApiService.WxPlaform
{
    [ClassLifetimeAttr(ClassLifetimeType.SingleInstance)]
    internal class WxPlatformService : IWxPlatformService
    {
        private readonly IWxPlaformTokenService _Token;
        private readonly IWxPlatformApi _PlatformApi;

        public WxPlatformService (IWxPlaformTokenService token, IWxPlatformApi platformApi)
        {
            this._Token = token;
            this._PlatformApi = platformApi;
        }
        public MiniLoginRes MiniLogin (string appId, string wxAppId, string code)
        {
            IComponentToken token = this._Token.GetToken(appId);
            return this._PlatformApi.MiniLogin(token, wxAppId, code);
        }
        public WxAuthorization GetMerAuth (string appId, string code)
        {
            IComponentToken token = this._Token.GetToken(appId);
            return this._PlatformApi.GetMerAuth(token, code);
        }
        public WxMerInfo GetMerInfo (string appId, string wxAppId)
        {
            IComponentToken token = this._Token.GetToken(appId);
            return this._PlatformApi.GetMerInfo(token, wxAppId);
        }
        public string GetPreauthCode (string appId, out int expire)
        {
            IComponentToken token = this._Token.GetToken(appId);
            PreauthCode code = this._PlatformApi.GetPreauthCode(token);
            expire = code.expires_in;
            return code.pre_auth_code;
        }
    }
}
